package org.jeecg.modules.online.desform.excel.converter.impl;

import org.jeecg.common.constant.ProvinceCityArea;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.desform.excel.converter.channel.ForeseeConvert;
import org.jeecg.modules.online.desform.vo.widget.DesformWidget;


/**
 * 省市区换模式
 */
public class AreaLinkageConverter extends ForeseeConvert {

    ProvinceCityArea provinceCityArea;

    public AreaLinkageConverter(DesformWidget widget) {
        this.model = widget.getModel();
        this.provinceCityArea = SpringContextUtils.getBean(ProvinceCityArea.class);
    }

    @Override
    public String converterToVal(String txt) {
        if (oConvertUtils.isEmpty(txt)) {
            return null;
        }
        return provinceCityArea.getCode(txt);
    }

    @Override
    public String converterToTxt(String val) {
        if (oConvertUtils.isEmpty(val)) {
            return null;
        }
        return provinceCityArea.getText(val);
    }

}
